<template>
  <div class="loginbody">
    <div class="logindata">
      <div class="logintext">
        <h2>注册</h2>
      </div>
      <div class="formdata">
        <el-form ref="form" :model="form" :rules="rules">
          <el-form-item prop="username">
            <el-input
              v-model="form.username"
              clearable
              placeholder="请输入账号"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="form.password"
              clearable
              placeholder="请输入密码"
              show-password
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="tool">
        <!-- <div>
          <el-checkbox v-model="checked" @change="remenber"
            >记住密码</el-checkbox
          >
        </div>
        <div>
          <span class="shou" @click="forgetpas">忘记密码？</span>
        </div> -->
      </div>
      <div class="butt">
        <el-button type="primary" @click.native.prevent="login()"
          >登录</el-button
        >
        <el-button class="shou" @click="register('form')">注册</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        password: "",
        username: "",
      },
      checked: false,
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { max: 10, message: "不能大于10个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { max: 10, message: "不能大于10个字符", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    login() {
      this.$router.push("login");
    },
    register(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.$http
            .post(
              "/register" +
                "?username=" +
                this.form.username +
                "&password=" +
                this.form.password
            )
            .then((res) => {
              console.log(res);
              if (res.data.status == 0) {
                // 注册成功
                this.$notify({
                  title: "注册成功",
                  type: "success",
                });
                this.$router.push("/login");
              } else {
                this.$notify.error({
                  title: "注册失败",
                });
              }
            });
          return true;
        }
      });
    },
  },
};
</script>

<style scoped>
.loginbody {
  margin-left: -100px;
  width: 100%;
  height: 100%;
  min-width: 1000px;
  background-image: url("../../assets/images/login_bg.jpg");
  background-size: 100% 100%;
  overflow: auto;
  background-repeat: no-repeat;
  position: fixed;
  line-height: 100%;
  padding-top: 150px;
}

.logintext {
  margin-bottom: 20px;
  line-height: 50px;
  text-align: center;
  font-size: 30px;
  font-weight: bolder;
  color: white;
  text-shadow: 2px 2px 4px #000000;
}

.logindata {
  width: 400px;
  height: 300px;
  transform: translate(-50%);
  margin-left: 50%;
}

.tool {
  display: flex;
  justify-content: space-between;
  color: #606266;
}

.butt {
  margin-top: 10px;
  text-align: center;
}

.shou {
  cursor: pointer;
  color: #606266;
}

/*ui*/
/* /deep/ .el-form-item__label {
  font-weight: bolder;
  font-size: 15px;
  text-align: left;
}

/deep/ .el-button {
  width: 100%;
  margin-bottom: 10px;

} */
</style>
